﻿using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

namespace Learning
{
    public class XRayDrawNormalPass : ScriptableRenderPass
    {
        private FilteringSettings _filtering;

        private List<ShaderTagId> _shaderTagIdList = new List<ShaderTagId>();
        
        private RenderStateBlock _renderStateBlock;
        
        public XRayDrawNormalPass()
        {
            renderPassEvent = RenderPassEvent.AfterRenderingOpaques;
            
            _filtering = new FilteringSettings(RenderQueueRange.opaque, LayerMask.GetMask("Character"));
            
            _shaderTagIdList.Add(new ShaderTagId("SRPDefaultUnlit"));
            _shaderTagIdList.Add(new ShaderTagId("UniversalForward"));
            _shaderTagIdList.Add(new ShaderTagId("UniversalForwardOnly"));
            
            _renderStateBlock = new RenderStateBlock(RenderStateMask.Nothing);
        }
        
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            DrawingSettings drawingSettings = CreateDrawingSettings(_shaderTagIdList, ref renderingData, renderingData.cameraData.defaultOpaqueSortFlags);

            context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref _filtering, ref _renderStateBlock);
        }
    }
}
